//
//  FMPersonVC.m
//  NewMyMusicAPP
//
//  Created by 11_wyq on 15/6/20.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FMPersonVC.h"

@interface FMPersonVC ()


@property(nonatomic,retain)CustomLabel *customLabel;
@property (retain ,nonatomic) MBProgressHUD *MBP;

@end

@implementation FMPersonVC

-(void)dealloc
{
    [_tableView release];
    [super dealloc];
    
    
}





- (void)viewDidLoad {
    [super viewDidLoad];
    

    //       给导航栏上放自定义label
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100 * WIDTH, 30 *HEIGHT)];
    [view setBackgroundColor:[UIColor clearColor]];
    self.navigationItem.titleView = view;
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH * (-375/2 + 55), 0, WIDTH * 375, HEIGHT * 30)];
    title.text = self.name;
    title.textAlignment = NSTextAlignmentCenter;
    title.textColor = [UIColor whiteColor];
    [title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];//加粗字体
    [view addSubview:title];
    
    
    self.hidesBottomBarWhenPushed = YES;//取消tabBar
   
    
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIImage *image2 = [UIImage imageNamed:@"VList_Left@2x.png"];
    image2 = [image2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image2 style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    

    
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIImage *image = [UIImage imageNamed:@"player2.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(player1)];
    
    
    
    
    
    
    
    self.view.backgroundColor = [UIColor blackColor];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, MYWIDTH, 618 * HEIGHT)];
    [self.view addSubview:self.tableView];
    
    self.array = [NSMutableArray array];

    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor blackColor];

    self.tableView.showsVerticalScrollIndicator = NO;//取消纵向滑条
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//取消cell之间的线
    
    //菊花(小黄人)
    [GiFHUD setGifWithImageName:@"xiaohuangren.gif"];
    [GiFHUD show];
    [self addHeader];//下拉刷新
    
    [self getMassage];
    
    [_tableView release];
    
}
-(void)addHeader
{
    __block FMPersonVC *FMperson=self;
    
    
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self getMassage];
        
        
        
    }];
    
    
}

-(void)getMassage
{
    
    
    
    
    
    
    NSString *string =[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/album/track/%@/true/1/30?device=iPhone",self.myId];
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
      //  NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        NSMutableDictionary *dic = responseObject;
        NSMutableDictionary *dic2 = [dic objectForKey:@"tracks"];
        NSMutableArray *array = [dic2 objectForKey:@"list"];

        for (NSMutableDictionary *smallDic in array) {
            FMPersonModel *model = [[FMPersonModel alloc]init];
            model.title = [smallDic objectForKey:@"title"];
            model.playUrl32 = [smallDic objectForKey:@"playUrl32"];
            model.trackId = [smallDic objectForKey:@"trackId"];
            model.albumTitle = [smallDic objectForKey:@"albumTitle"];
            model.likes = [smallDic objectForKey:@"likes"];
            model.playtimes = [smallDic objectForKey:@"playtimes"];
            model.coverLarge = [smallDic objectForKey:@"coverLarge"];
            [self.array addObject:model];
            [model release];
            
            
        }

        //刷新tableView
        [self.tableView reloadData];
       [GiFHUD dismiss];//菊花隐藏
        [self.tableView.header endRefreshing];//结束下拉
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        //[GiFHUD dismiss];//菊花隐藏
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的网络不给力,请检查网络设置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        
    }];
}


//区数量
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
    
}

//每个区cell的数量
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    
    return self.array.count ;
    
}


//每个cell上内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellName = @"myCell";
    FMPersonCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (cell == nil) {
        cell = [[FMPersonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
        
    }
 
        FMPersonModel *model = [self.array objectAtIndex:indexPath.row];
        cell.model = model;
    
    
    //渐变效果
    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    cell.alpha = 0.1;
    [UIView beginAnimations:@"rotation" context:NULL];
    [UIView setAnimationDuration:1.5];//时间
    cell.alpha = 1;
    [UIView commitAnimations];

  

    cell.selectionStyle = UITableViewCellSelectionStyleNone;//取消点击效果
    
    return  cell;
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 110;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FMPlayerVC *player = [FMPlayerVC shareHandleController];
    
    if ([DataHandle shareHandleController].monitorNetwork == NO) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您的网络不给力,请检查网络设置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

    FMPersonModel *model = [self.array objectAtIndex:indexPath.row];
    player.title = model.title;
    player.trackId = model.trackId;
    player.Audio = [NSMutableArray arrayWithArray:self.array];

    
    player.count = 2;
    player.indexPath = indexPath;
    
    
    NSLog(@"888");
    
    
    NSMutableArray *array = [[DataHandle shareHandleController]selectCollect];
    for (FMPersonModel *collectModel in array) {
        if ([collectModel.title isEqualToString:model.title]) {
            player.isCollection = YES;
             [self.navigationController pushViewController:player animated:YES];
            
            return;
        }
    }
    
    player.isCollection = NO;
     [self.navigationController pushViewController:player animated:YES];
    
    
    
   
    
    
   
    
}


#pragma mark ---进入播放页面
-(void)player1
{
    FMPlayerVC *playerVC = [FMPlayerVC shareHandleController];
    if (playerVC.trackId == nil) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您当前没有听电台哟~~" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        return;
        
    }
    NSLog(@"= = = = = ");

    [self.navigationController pushViewController:playerVC animated:YES];
}




-(void)back
{
    [GiFHUD dismiss];//菊花隐藏
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
